<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="lcy">
    <script src="jquery-3.1.1.js"></script>
    <title></title>
    <style>
        ul,li{
            padding: 0;
            margin: 0;
            list-style: none;
        }
        .content{
            width: 520px;
            height: 280px;
            margin: 100px auto;
            position: relative;
        }
        .content .pic li{
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        .content .pic li.current{
            display: block;
        }
        .content .indictor{
            position: absolute;
            left: 5px;
            bottom: 5px;
        }
        .content .indictor li{
            float: left;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: green;
            text-align: center;
            margin: 5px;
            color: white;
            cursor: pointer;
        }
        .content .indictor li.active{
            background-color: darkred;
        }
        .content .page{
            position: absolute;
            right: 10px;
            bottom: 10px;
            color: white;
        }
        .content .page span{
            display: inline-block;
            width: 30px;
            height: 30px;
            background-color: rgba(0, 0, 0, 0.3);
            line-height: 30px;
            text-align: center;
            font-size: 30px;
            margin: 0 5px;
            cursor: pointer;
        }
        .content .page span:hover{
            background-color: rgba(0, 0, 0, 0.7);
        }
    </style>
</head>
<body>
    <div class="content">
        <ul class="pic">
            <li class="current"><a href="#"><img src="images/01.jpg" alt=""></a></li>
            <li><a href="#"><img src="images/02.jpg" alt=""></a></li>
            <li><a href="#"><img src="images/03.jpg" alt=""></a></li>
            <li><a href="#"><img src="images/04.jpg" alt=""></a></li>
            <li><a href="#"><img src="images/05.jpg" alt=""></a></li>
        </ul>
        <!--指示灯-->
        <ul class="indictor">
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <!--左右按钮-->
        <div class="page"><span class="pre">&lt;</span><span class="next">&gt;</span></div>
    </div>
</body>
</html>
<script>
    // 定义图片的索引值 初始是0 第一张图
    var index=0;
    // 1.自动切换
    var timer=setInterval(nextimg,1000);

    // 下一张 设置专门的方法来存储图片的索引
    function nextimg(){
        index = (index==$('.pic li').length-1) ? 0 : (index+1);
        showimg();
    }
    // 上一张
    function preimg(){
        index=index==0?$('.pic li').length-1:index-1;
        showimg();
    }
    // 展示图片和指示灯
    function showimg(){
        // 根据索引值显示当前图片 隐藏其他图片
        $('.pic li').eq(index).show().siblings().hide();
        $('.indictor li').eq(index).addClass('active').siblings().removeClass('active');
    }
    // 2.悬停切换
    $('.indictor li').hover(function(){
        // 鼠标进入指示灯 停止自动切换
        clearInterval(timer);
        // 获取当前选中的li标签的索引值
        index=$(this).index();
        showimg();
    },function(){
        // 鼠标出来 恢复自动切换
        timer=setInterval(nextimg,1000);
    });
    // 上一张
        $('.page .pre').click(function(){
            preimg();
        })
        // 下一张
        $('.page .next').click(function(){
            nextimg();
        })
    // 3.点击按钮切换
    $('.content').hover(function(){
        clearInterval(timer);
    },function(){
        timer=setInterval(nextimg,1000);
    });
</script>